<template>
	<view class="container">
		<view class="tip">说明: 请长按图片进行保存</view>
		<movable-area scale-area style="width: 100%;">
			<movable-view direction="all"  scale="true" scale-min="1" scale-max="10" :scale-value="scale" style="width: 100%;">
				<img :src="imgUrl" width="100%" height="auto" @click="getImgIndex(0)">
			</movable-view>
		</movable-area>
		
	</view>
</template>

<script>
	import pdfToImg from "@/components/pdfToImg.vue"
	export default {
		data() {
			return {
				pdfStream: "",
				errorTip: "电子发票图片加载失败，请重新尝试加载或联系街道工作人员处理",
				imgUrl: "",
				dzfpData: "",
				scale:1
			};
		},
		components: {
			pdfToImg
		},
		onLoad(e) {
			console.log("参数", e)
			let data = JSON.parse(e.data)
			this.dzfpData = data
			this.getPdfWj()
		},
		methods: {
			// 获取pdf文件流
			async getPdfWj() {
				let that = this
				let params = {
					id: this.dzfpData.fpId,
					djh: this.dzfpData.djh,
					fpdm: this.dzfpData.fpdm,
					fphm: this.dzfpData.fphm,
					wjlx: "jpg"
				}
				// let params={
				// 	"id":"a76691b29a774cd189c0973de27aee16",
				// 	"wjlx":"jpg"
				// }
				let url = process.env.VUE_APP_BASE_URL + '/back/yst/dzfp/previewYstDzfp'

				uni.request({
					url: url, // 替换成你的文件的URL
					responseType: 'arraybuffer', // 设置响应数据类型为 arraybuffer
					method: 'post',
					header: {},
					sslVerify: false,
					withCredentials: true,
					data: params,
					success(res) {
						const base64 = uni.arrayBufferToBase64(res.data)
						that.imgUrl = 'data:image/jpg;base64,' + base64
						// console.log(that.imgUrl)
					},
					fail(error) {
						uni.showModal({
							title: '提示',
							content: that.errorTip,
							confirmColor: '#000000', //确定字体颜色
							showCancel: false, //没有取消按钮的弹框 
							buttonText: '确定',
							success: function(res) {
								if (res.confirm) {
									uni.navigateBack();
								}
							}
						});
					}
				});
			},
			// 点击图片预览
			getImgIndex(index) {
				uni.previewImage({
					urls: [this.imgUrl],
					current: index
				})
			},

		},
	};
</script>
<style>
	.container{
		min-height: 100vh;
	}
	.tip {
		padding: 20rpx 10rpx;
		font-size: 30rpx;
		color: black;
	}

	.listCanvas {
		width: 0;
		height: 0;
	}
</style>